package com.coocaa.aries.jmeter.thread;

import com.coocaa.aries.jmeter.entity.ExtTestCaseInfoEntity;

import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author bijiahao
 * @description
 * @date 2020/1/6 11:35
 */
public class ThreadExecMgr {
    public static LinkedBlockingQueue<ExtTestCaseInfoEntity> deque = new LinkedBlockingQueue<>(100);
    private static AtomicBoolean isExecuing = new AtomicBoolean(false);

    public static void offer(ExtTestCaseInfoEntity entity) {
        deque.offer(entity);
    }

    public static ExtTestCaseInfoEntity poll() {
        return deque.poll();
    }


    public static boolean isExecuing() {
        return isExecuing.get();
    }

    public static void set(boolean newValue) {
        isExecuing.set(newValue);
    }

    public static void remove(Integer id) {
        Iterator<ExtTestCaseInfoEntity> it = deque.iterator();
        while (it.hasNext()) {
            ExtTestCaseInfoEntity entity = it.next();
            if (Objects.equals(entity.getId(), id)) {
                it.remove();
            }
        }
    }

}
